#include "AnimationSprite.h"
using namespace cocos2d;
CAnimationSprite::CAnimationSprite(void)
{
	pObject_=NULL;
}

CAnimationSprite::~CAnimationSprite(void)
{
}

bool CAnimationSprite::init(const std::string arrayPic[],int nNum,float fIntervalTime,bool bRepeat)
{
	bool bRet=false;
	do 
	{
		if (!CCSprite::init())
		{
			return false;
		}
		pObject_ = CAnimationObject::node(arrayPic,nNum,0.1);
		if (!pObject_)
		{
			break;
		}
		CCActionInterval *pActionInterval= CCAnimate::actionWithAnimation(pObject_);
		if (!pActionInterval)
		{
			break;
		}
		if(bRepeat)
		{
			pActionInterval=CCRepeatForever::actionWithAction(pActionInterval);
		}
		if (!pActionInterval)
		{
			break;
		}
		this->runAction(pActionInterval);
		bRet=true;
	} while(false);
	return bRet;
}

CAnimationSprite * CAnimationSprite::node(const std::string arrayPic[],int nNum,float fIntervalTime,bool bRepeat)
{
	CAnimationSprite *pNode=new CAnimationSprite;
	if (pNode)
	{
		pNode->autorelease();
		if (pNode->init(arrayPic,nNum,fIntervalTime,bRepeat))
		{
			return pNode;
		}
	}
	return NULL;
}